﻿////////////////////////////////////////////////////////////////
///
/// File: TestProject1.cs
/// Author: Lucio Davide Spano
/// Last update: 27 July 2012
/// Description: Unit tests for the GestIT library
/// To do: 
/// ------------------------------------------------------------
/// Copyright (c) 2012 Lucio Davide Spano 
///                     (lucio.davide.spano@isti.cnr.it)
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------
////////////////////////////////////////////////////////////////

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using GestIT;
using TouchGestIT;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        
        [TestMethod]
        public void TestMethod1()
        {
            SimpleTmpExp touchStart = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            touchMove.Iterative = true;
            SimpleTmpExp touchEnd = new SimpleTmpExp(new TouchContent(TouchType.End, 1));

            BinaryTmpExp b1 = new BinaryTmpExp(touchMove, touchEnd, TmpOperator.Disabling);
            BinaryTmpExp pan = new BinaryTmpExp(touchStart, b1, TmpOperator.Enabling);

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(pan);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));
            Assert.AreEqual(ExecState.Completed, pan.State);
        }

        [TestMethod]
        public void TestMethod2()
        {
            // this method test the correct interpretation of a pinch gesture
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));

            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            SimpleTmpExp touchMove2 = new SimpleTmpExp(new TouchContent(TouchType.Move, 2));
            touchMove1.Iterative = true;
            touchMove2.Iterative = true;

            SimpleTmpExp touchEnd1 = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            SimpleTmpExp touchEnd2 = new SimpleTmpExp(new TouchContent(TouchType.End, 2));

            ComplexTmpExp start = new ComplexTmpExp();
            start.Operator = TmpOperator.OrderIndependence;
            start.AddOperand(touchStart1);
            start.AddOperand(touchStart2);

            BinaryTmpExp move = new BinaryTmpExp(touchMove1, touchMove2, TmpOperator.Parallel);

            ComplexTmpExp end = new ComplexTmpExp();
            end.Operator = TmpOperator.OrderIndependence;
            end.AddOperand(touchEnd1);
            end.AddOperand(touchEnd2);

            BinaryTmpExp b1 = new BinaryTmpExp(move, end, TmpOperator.Disabling);

            BinaryTmpExp pinch = new BinaryTmpExp(start, b1, TmpOperator.Enabling);


            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(pinch);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            Assert.AreEqual(ExecState.Completed, start.State);
            Assert.AreEqual(ExecState.Enabled, touchMove1.State);
            Assert.AreEqual(ExecState.Enabled, touchMove2.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, touchMove1.State);
            Assert.AreEqual(ExecState.Enabled, touchMove2.State);
            Assert.AreEqual(ExecState.Performing, pinch.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.End));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));

            Assert.AreEqual(ExecState.Completed, pinch.State);
        }

        [TestMethod]
        public void TestMethod3()
        {
            //declare a pan
            SimpleTmpExp touchStart = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            touchMove.Iterative = true;
            SimpleTmpExp touchEnd = new SimpleTmpExp(new TouchContent(TouchType.End, 1));

            BinaryTmpExp b1 = new BinaryTmpExp(touchMove, touchEnd, TmpOperator.Disabling);
            BinaryTmpExp pan = new BinaryTmpExp(touchStart, b1, TmpOperator.Enabling);

            // declare pinch
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));

            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            SimpleTmpExp touchMove2 = new SimpleTmpExp(new TouchContent(TouchType.Move, 2));
            touchMove1.Iterative = true;
            touchMove2.Iterative = true;

            SimpleTmpExp touchEnd1 = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            SimpleTmpExp touchEnd2 = new SimpleTmpExp(new TouchContent(TouchType.End, 2));

            ComplexTmpExp start = new ComplexTmpExp();
            start.Operator = TmpOperator.OrderIndependence;
            start.AddOperand(touchStart1);
            start.AddOperand(touchStart2);

            BinaryTmpExp move = new BinaryTmpExp(touchMove1, touchMove2, TmpOperator.Parallel);

            ComplexTmpExp end = new ComplexTmpExp();
            end.Operator = TmpOperator.OrderIndependence;
            end.AddOperand(touchEnd1);
            end.AddOperand(touchEnd2);

            BinaryTmpExp b2 = new BinaryTmpExp(move, end, TmpOperator.Disabling);

            BinaryTmpExp pinch = new BinaryTmpExp(start, b2, TmpOperator.Enabling);

            // declare the whole gesture

            BinaryTmpExp gesture = new BinaryTmpExp(pan, pinch, TmpOperator.Choice);
            gesture.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(gesture);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            Assert.AreEqual(ExecState.Enabled, pan.State);
            Assert.AreEqual(ExecState.Enabled, pinch.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Performing, pan.State);
            Assert.AreEqual(ExecState.Performing, pinch.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            Assert.AreEqual(ExecState.Completed, start.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            Assert.AreEqual(ExecState.Disabled, pan.State);
            Assert.AreEqual(ExecState.Enabled, touchMove1.State);
            Assert.AreEqual(ExecState.Enabled, touchMove2.State);
            Assert.AreEqual(ExecState.Enabled, touchEnd1.State);
            Assert.AreEqual(ExecState.Enabled, touchEnd2.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, touchEnd1.State);
            Assert.AreEqual(ExecState.Enabled, touchEnd2.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, touchEnd1.State);
            Assert.AreEqual(ExecState.Enabled, touchEnd2.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.End));
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Performing, end.State);
            Assert.AreEqual(ExecState.Enabled, touchEnd1.State);
            Assert.AreEqual(ExecState.Completed, touchEnd2.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));

            Assert.AreEqual(ExecState.Enabled, gesture.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));
            Assert.AreEqual(ExecState.Enabled, gesture.State);
        }

        [TestMethod]
        public void TestMethod4()
        {
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            BinaryTmpExp bexp1 = new BinaryTmpExp(touchStart1, touchMove1, TmpOperator.Enabling);
            bexp1.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(bexp1);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Completed, touchStart1.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Completed, touchMove1.State);
            Assert.AreEqual(ExecState.Enabled, bexp1.State);
            Assert.AreEqual(ExecState.Enabled, touchStart1.State);
        }

        [TestMethod]
        public void TestMethod5()
        {
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            touchStart1.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(touchStart1);
            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, touchStart1.State);
        }
        
        [TestMethod]
        public void TestMethod6()
        {
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            BinaryTmpExp bexp1 = new BinaryTmpExp(touchStart1, touchMove1, TmpOperator.Enabling);
            bexp1.Iterative = true;
            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(bexp1);
            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            
            Assert.AreEqual(ExecState.Enabled, touchStart1.State);
            Assert.AreNotEqual(null, touchStart1.Token);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, touchStart1.State);

        }

        [TestMethod]
        public void TestMethod7()
        {
            SimpleTmpExp openHand = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp openHand2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            openHand2.Iterative = true;
            SimpleTmpExp grab = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));
            BinaryTmpExp bexp1 = new BinaryTmpExp(openHand2, grab, TmpOperator.Disabling);
            BinaryTmpExp bexp3 = new BinaryTmpExp(openHand, bexp1, TmpOperator.Enabling);
            
            SimpleTmpExp move = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            move.Iterative = true;

            SimpleTmpExp release = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            BinaryTmpExp bexp2 = new BinaryTmpExp(move, release, TmpOperator.Disabling);

            BinaryTmpExp gesture = new BinaryTmpExp(bexp3, bexp2, TmpOperator.Enabling);
            gesture.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(gesture);
            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Enabled, openHand2.State);
            Assert.AreEqual(ExecState.Enabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Enabled, openHand2.State);
            Assert.AreEqual(ExecState.Enabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Enabled, openHand2.State);
            Assert.AreEqual(ExecState.Enabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Enabled, openHand2.State);
            Assert.AreEqual(ExecState.Enabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Enabled, openHand2.State);
            Assert.AreEqual(ExecState.Enabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Completed, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Enabled, move.State);
            Assert.AreEqual(ExecState.Enabled, release.State);
            Assert.AreEqual(ExecState.Performing, gesture.State);
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.End));
            Assert.AreEqual(ExecState.Enabled, gesture.State);
        }
        


        [TestMethod]
        public void TestMethod8()
        {
            SimpleTmpExp openHand = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp openHand2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            openHand2.Iterative = true;
            SimpleTmpExp grab = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));
            BinaryTmpExp bexp1 = new BinaryTmpExp(openHand2, grab, TmpOperator.Disabling);
            BinaryTmpExp bexp3 = new BinaryTmpExp(openHand, bexp1, TmpOperator.Enabling);

            SimpleTmpExp move = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            move.Iterative = true;

            SimpleTmpExp release = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            BinaryTmpExp bexp2 = new BinaryTmpExp(move, release, TmpOperator.Disabling);

            BinaryTmpExp gesture = new BinaryTmpExp(bexp3, bexp2, TmpOperator.Enabling);
            gesture.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(gesture);
            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Move));
            Assert.AreEqual(ExecState.Enabled, openHand.State);
            Assert.AreEqual(ExecState.Disabled, openHand2.State);
            Assert.AreEqual(ExecState.Disabled, grab.State);
            Assert.AreEqual(ExecState.Disabled, move.State);
            Assert.AreEqual(ExecState.Disabled, release.State);
            Assert.AreEqual(ExecState.Enabled, gesture.State);
        }

        [TestMethod]
        public void TestMethod9()
        {
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));

            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            SimpleTmpExp touchMove2 = new SimpleTmpExp(new TouchContent(TouchType.Move, 2));
            touchMove1.Iterative = true;
            touchMove2.Iterative = true;

            SimpleTmpExp touchEnd1 = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            SimpleTmpExp touchEnd2 = new SimpleTmpExp(new TouchContent(TouchType.End, 2));

            ComplexTmpExp start = new ComplexTmpExp();
            start.Operator = TmpOperator.OrderIndependence;
            start.AddOperand(touchStart1);
            start.AddOperand(touchStart2);

            BinaryTmpExp move = new BinaryTmpExp(touchMove1, touchMove2, TmpOperator.Parallel);

            ComplexTmpExp end = new ComplexTmpExp();
            end.Operator = TmpOperator.OrderIndependence;
            end.AddOperand(touchEnd1);
            end.AddOperand(touchEnd2);

            BinaryTmpExp b1 = new BinaryTmpExp(move, end, TmpOperator.Disabling);

            BinaryTmpExp pinch = new BinaryTmpExp(start, b1, TmpOperator.Enabling);

            pinch.Iterative = true;
            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(pinch);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            // simulate a recognition error
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            // at this time the gesture should restart
            Assert.AreEqual(ExecState.Enabled, pinch.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.End));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));

            Assert.AreEqual(ExecState.Enabled, pinch.State);
        }

        [TestMethod]
        public void TestMethod10()
        {
            //declare a pan
            SimpleTmpExp touchStart = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            touchMove.Iterative = true;
            SimpleTmpExp touchEnd = new SimpleTmpExp(new TouchContent(TouchType.End, 1));

            BinaryTmpExp b1 = new BinaryTmpExp(touchMove, touchEnd, TmpOperator.Disabling);
            BinaryTmpExp pan = new BinaryTmpExp(touchStart, b1, TmpOperator.Enabling);

            // declare pinch
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));

            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            SimpleTmpExp touchMove2 = new SimpleTmpExp(new TouchContent(TouchType.Move, 2));
            touchMove1.Iterative = true;
            touchMove2.Iterative = true;

            SimpleTmpExp touchEnd1 = new SimpleTmpExp(new TouchContent(TouchType.End, 1));
            SimpleTmpExp touchEnd2 = new SimpleTmpExp(new TouchContent(TouchType.End, 2));

            ComplexTmpExp start = new ComplexTmpExp();
            start.Operator = TmpOperator.OrderIndependence;
            start.AddOperand(touchStart1);
            start.AddOperand(touchStart2);

            BinaryTmpExp move = new BinaryTmpExp(touchMove1, touchMove2, TmpOperator.Parallel);

            ComplexTmpExp end = new ComplexTmpExp();
            end.Operator = TmpOperator.OrderIndependence;
            end.AddOperand(touchEnd1);
            end.AddOperand(touchEnd2);

            BinaryTmpExp b2 = new BinaryTmpExp(move, end, TmpOperator.Disabling);

            BinaryTmpExp pinch = new BinaryTmpExp(start, b2, TmpOperator.Enabling);

            // declare the whole gesture

            BinaryTmpExp gesture = new BinaryTmpExp(pan, pinch, TmpOperator.Choice);
            gesture.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(gesture);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            Assert.AreEqual(ExecState.Completed, start.State);
     
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
     
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.End));
            // simulate an error
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));

            Assert.AreEqual(ExecState.Enabled, pinch.State);
            Assert.AreEqual(ExecState.Enabled, touchStart1.State);
            Assert.AreEqual(ExecState.Enabled, touchStart2.State);
            Assert.AreEqual(ExecState.Enabled, start.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 2, TouchType.Start));
            Assert.AreEqual(ExecState.Completed, start.State);

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 2, TouchType.End));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));
         
            Assert.AreEqual(ExecState.Enabled, gesture.State);
        }

        [TestMethod]
        public void TestMethod11()
        {
            SimpleTmpExp touchStart = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchMove = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            touchMove.Iterative = true;
            SimpleTmpExp touchEnd = new SimpleTmpExp(new TouchContent(TouchType.End, 1));

            BinaryTmpExp b1 = new BinaryTmpExp(touchMove, touchEnd, TmpOperator.Disabling);
            BinaryTmpExp pan = new BinaryTmpExp(touchStart, b1, TmpOperator.Enabling);
            pan.Iterative = true;

            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(pan);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));

            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(200.0, 200.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.Move));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(300.0, 300.0, 1, TouchType.End));
            Assert.AreEqual(ExecState.Enabled, pan.State);
        }
        
        [TestMethod]
        public void TestMethod12()
        {
            SimpleTmpExp touchStart1 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart2 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));
            touchStart1.Iterative = true;
            touchStart2.Iterative = true;

            SimpleTmpExp touchStart11 = new SimpleTmpExp(new TouchContent(TouchType.Start, 1));
            SimpleTmpExp touchStart22 = new SimpleTmpExp(new TouchContent(TouchType.Start, 2));

            SimpleTmpExp touchMove1 = new SimpleTmpExp(new TouchContent(TouchType.Move, 1));
            SimpleTmpExp touchMove2 = new SimpleTmpExp(new TouchContent(TouchType.Move, 2));

            BinaryTmpExp bexp1 = new BinaryTmpExp(touchStart1, touchStart2, TmpOperator.SynchronizedParallel);
            BinaryTmpExp bexp2 = new BinaryTmpExp(touchStart11, touchMove1, TmpOperator.Enabling);
            BinaryTmpExp bexp3 = new BinaryTmpExp(touchStart22, touchMove2, TmpOperator.Enabling);
            BinaryTmpExp bexp4 = new BinaryTmpExp(bexp2, bexp3, TmpOperator.SynchronizedParallel);
            BinaryTmpExp gesture = new BinaryTmpExp(bexp1, bexp4, TmpOperator.Disabling);


            Emitter touchEmitter = new Emitter();
            touchEmitter.SetGestureDescription(gesture);

            touchEmitter.StartRecognition(new TouchToken(PointTracking.Last));
            touchEmitter.FeedDeviceEvent(new TouchEventArgs(100.0, 100.0, 1, TouchType.Start));
            Assert.AreEqual(ExecState.Disabled, bexp1.State);
            Assert.AreEqual(ExecState.Disabled, touchStart1.State);
            Assert.AreEqual(ExecState.Disabled, touchStart2.State);
        }
    }


}
